#!/bin/bash

script_dirs="bin monitors setup tests"

bash=$(compgen -b)
busybox=$(busybox --list)
coreutils=$(dpkg -L coreutils | grep bin/ | sed 's#.*/##g')
bin_sbin=$(ls /bin; ls /sbin)
android5="
ATFWD-daemon
adb
am
app_process
app_process32
applypatch
appops
appwidget
atrace
bcc
bdAddrLoader
blkid
bmgr
bootanimation
bridgemgrd
btnvtool
bu
bugreport
cat
chcon
chmod
chown
clatd
clear
cmp
conn_init
content
cp
dalvikvm
dalvikvm32
date
dd
debuggerd
dex2oat
df
dhcpcd
diag_klog
diag_mdlog
dmesg
dnsmasq
dpm
drmserver
ds_fmc_appd
du
dumpstate
dumpsys
e2fsck
efsks
fsck_msdos
getenforce
getevent
getprop
getsebool
grep
gzip
hci_qcomm_init
hd
hostapd
id
idmap
ifconfig
iftop
ime
input
insmod
install-recovery.sh
installd
ioctl
ionice
ip
ip6tables
iptables
keystore
kill
ks
linker
lmkd
ln
load_policy
log
logcat
logd
logwrapper
ls
lsmod
lsof
make_ext4fs
md5
mdnsd
media
mediaserver
mkdir
mknod
mkswap
mm-qcamera-app
mm-qcamera-daemon
monkey
mount
mpdecision
mtpd
mv
nandread
ndc
netcfg
netd
netmgrd
netstat
newfs_msdos
nl_listener
nohup
notify
oatdump
patchoat
ping
ping6
pm
port-bridge
pppd
printenv
ps
qcks
qmuxd
qseecomd
racoon
radish
readlink
reboot
renice
requestsync
resize2fs
restorecon
rild
rm
rmdir
rmmod
rmt_storage
route
run-as
runcon
schedtest
schedtop
screencap
screenrecord
sdcard
sendevent
sensors.qcom
sensorservice
service
servicemanager
setenforce
setprop
setsebool
settings
sh
sleep
smd
start
stop
surfaceflinger
svc
swapoff
swapon
sync
tc
thermald
toolbox
top
touch
uiautomator
umount
uncrypt
uptime
usbhub
usbhub_init
v4l2-qcamera-app
vdc
vmstat
vold
watchprops
wipe
wm
wpa_supplicant
"

commands=$(echo -e "$coreutils\n$bin_sbin" | grep -v -x -F -f <(echo "$bash"))
commands=$(echo -e "$coreutils\n$bin_sbin" | grep -v -x -F -f <(echo "$busybox"))
commands=$(echo -e "$coreutils\n$bin_sbin" | grep -v -x -F -f <(echo -e "$android5\n$bash"))

for cmd in $commands
do
	grep --color -r -E "(^|if|\(|\`|cmd|command|exec|\||;|&|bin/)\s*\<$cmd\s" $script_dirs
done
